﻿//-------------------------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2011 , DotNet, Ltd.
//-------------------------------------------------------------------------------------

using System;
using System.Data;
using System.Reflection;

namespace DotNet.Service
{
    using DotNet.Business;
    using DotNet.DbUtilities;
    using DotNet.IService;
    using DotNet.Model;
    using DotNet.Utilities;

    /// <summary>
    /// OrganizeService
    /// 组织机构服务
    ///
    /// 修改纪录
    ///
    ///		2007.08.15 版本：2.2 DotNet 改进运行速度采用 WebService 变量定义 方式处理数据。
    ///		2007.08.14 版本：2.1 DotNet 改进运行速度采用 Instance 方式处理数据。
    ///     2007.06.11 版本：1.3 DotNet 加入调试信息#if (DEBUG)。
    ///     2007.06.04 版本：1.2 DotNet 加入WebService。
    ///     2007.05.29 版本：1.1 DotNet 排版，修改，完善。
    ///		2007.05.11 版本：1.0 DotNet 窗体与数据库连接的分离。
    ///
    /// 版本：2.2
    ///
    /// <author>
    ///		<name>DotNet</name>
    ///		<date>2007.08.15</date>
    /// </author>
    /// </summary>
    public class OrganizeService : System.MarshalByRefObject, IOrganizeService
    {
        /// <summary>
        /// 用户中心数据库连接
        /// </summary>
        private readonly string UserCenterDbConnection = BaseSystemInfo.UserCenterDbConnection;

        public string Add(BaseUserInfo userInfo, BaseOrganizeEntity organizeEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif
            statusCode = string.Empty;
            statusMessage = string.Empty;

            string returnValue = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.Add(organizeEntity, out statusCode);
                statusMessage = organizeManager.GetStateMessage(statusCode);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public string AddByDetail(BaseUserInfo userInfo, string parentId, string code, string fullName, string categoryId, string outerPhone, string innerPhone, string fax, bool enabled, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif
            statusCode = string.Empty;
            statusMessage = string.Empty;

            string returnValue = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.AddByDetail(parentId, code, fullName, categoryId, outerPhone, innerPhone, fax, enabled, out statusCode);
                statusMessage = organizeManager.GetStateMessage(statusCode);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">操作员</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseOrganizeEntity GetEntity(BaseUserInfo userInfo, string id)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif
            BaseOrganizeEntity organizeEntity = null;

            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                organizeEntity = organizeManager.GetEntity(int.Parse(id));
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return organizeEntity;
        }

        public DataTable GetDT(BaseUserInfo userInfo)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.GetDataTable(BaseOrganizeTable.FieldDeletionStateCode, 0, BaseOrganizeTable.FieldSortCode);
                dataTable.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                dataTable.TableName = BaseOrganizeTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public DataTable GetDTByParent(BaseUserInfo userInfo, string parentId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.GetDataTable(BaseOrganizeTable.FieldParentId, parentId, BaseOrganizeTable.FieldDeletionStateCode, 0, BaseOrganizeTable.FieldSortCode);
                dataTable.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                dataTable.TableName = BaseOrganizeTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public DataTable GetInnerOrganizeDT(BaseUserInfo userInfo, string organizeId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.GetInnerOrganize(organizeId);
                dataTable.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                dataTable.TableName = BaseOrganizeTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public DataTable GetCompanyDT(BaseUserInfo userInfo, string organizeId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.GetCompanyDT(organizeId);
                dataTable.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                dataTable.TableName = BaseOrganizeTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public DataTable GetDepartmentDT(BaseUserInfo userInfo, string organizeId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.GetDepartmentDT(organizeId);
                dataTable.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                dataTable.TableName = BaseOrganizeTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public DataTable GetChildrenStaffs(BaseUserInfo userInfo, string organizeId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.GetChildrenStaffs(organizeId);
                dataTable.DefaultView.Sort = BaseStaffTable.FieldSortCode;
                dataTable.TableName = BaseStaffTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public DataTable GetParentChildrenStaffs(BaseUserInfo userInfo, string organizeId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.GetParentChildrenStaffs(organizeId);
                dataTable.DefaultView.Sort = BaseStaffTable.FieldSortCode;
                dataTable.TableName = BaseStaffTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public DataTable Search(BaseUserInfo userInfo, string organizeId, string searchValue)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            DataTable dataTable = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);

                // 获得组织机构列表
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                dataTable = organizeManager.Search(string.Empty, searchValue);
                dataTable.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                dataTable.TableName = BaseOrganizeTable.TableName;
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return dataTable;
        }

        public int Update(BaseUserInfo userInfo, BaseOrganizeEntity organizeEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif
            statusCode = string.Empty;
            statusMessage = string.Empty;

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.Update(organizeEntity, out statusCode);
                statusMessage = organizeManager.GetStateMessage(statusCode);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public int Delete(BaseUserInfo userInfo, string id)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.Delete(id);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public int BatchDelete(BaseUserInfo userInfo, string[] ids)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.BatchDelete(ids);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        /// <summary>
        /// 批量做删除标志
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int SetDeleted(BaseUserInfo userInfo, string[] ids)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif
            int returnValue = 0;

            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.SetDeleted(ids);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public int BatchSave(BaseUserInfo userInfo, DataTable dataTable)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.BatchSave(dataTable);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public int MoveTo(BaseUserInfo userInfo, string organizeId, string parentId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.MoveTo(organizeId, parentId);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public int BatchMoveTo(BaseUserInfo userInfo, string[] organizeIds, string parentId)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                for (int i = 0; i < organizeIds.Length; i++)
                {
                    returnValue += organizeManager.MoveTo(organizeIds[i], parentId);
                }
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public int BatchSetCode(BaseUserInfo userInfo, string[] ids, string[] codes)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.BatchSetCode(ids, codes);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }

        public int BatchSetSortCode(BaseUserInfo userInfo, string[] ids)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            int returnValue = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open(UserCenterDbConnection);
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                returnValue = organizeManager.BatchSetSortCode(ids);
                BaseLogManager.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception ex)
            {
                BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                throw ex;
            }
            finally
            {
                dbHelper.Close();
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif
            return returnValue;
        }
    }
}